#include <dirent.h>
#include <stdio.h>
#include <string.h>

int count = 0;

void getName(char *path) {
    DIR *dir = opendir(path);
    if (dir == NULL) {
        perror("opendir");
        return;
    }

    struct dirent *dent;
    while ((dent = readdir(dir)) != NULL) {
        if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) {
            continue;
        }

        if (dent->d_type == DT_DIR) {
            char newPath[500];
            snprintf(newPath, sizeof(newPath), "%s/%s", path, dent->d_name);
            getName(newPath);  // 递归处理子目录
        } else {
            if(strcmp(dent->d_name,"1.txt") == 0){
             count++;
            printf("找到1.txt：%s/%s\n",path,dent->d_name);
        }
    }
}
    closedir(dir);  // 关闭目录
}

int main(int argc, char *argv[]) {
    char *start_path = (argc > 1) ? argv[1] : ".";  // 允许从命令行参数指定目录
    getName(start_path);
    printf("数量为'1.txt'files found:%d\n",count);
    return 0;
}         
